package com.ilibrary.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ilibrary.base.MyAjaxAction;
import com.ilibrary.service.NewsCategoryService;
import com.ilibrary.web.dto.ResultDto;
import com.ilibrary.web.vo.NewsCategoryVO;

public class DoQueryNewsCategoryListAction extends MyAjaxAction {

	private NewsCategoryService newsCategoryService;
	
	public NewsCategoryService getNewsCategoryService() {
		return newsCategoryService;
	}
	public void setNewsCategoryService(NewsCategoryService newsCategoryService) {
		this.newsCategoryService = newsCategoryService;
	}

	@Override
	protected JSONObject doExecute(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		JSONObject joo = null;
		ResultDto<NewsCategoryVO> resultDto = newsCategoryService.findAll();
		List<NewsCategoryVO> newsCategoryVOList = resultDto.getResultList();
		for (NewsCategoryVO newsCategoryVO : newsCategoryVOList) {
			joo = new JSONObject();
			joo.put("newsCategoryId", newsCategoryVO.getNewsCategoryId());
			joo.put("newsCategoryName", newsCategoryVO.getNewsCategoryName());
			joo.put("newsCategoryDesc", newsCategoryVO.getNewsCategoryDesc());
			ja.add(joo);
		}
		jo.put("data", ja);
		return jo;
	}

}
